﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.IO;

namespace Infrastructure.Aspect.Services.Network
{
    public class NetworkService: INetworkService
    {

        public void DownloadFile(string address, string output)
        {
            WebClient wc = new WebClient();
            wc.Proxy = null;
            wc.DownloadFile(address, output);
            wc.Dispose();
        }


        public string DownloadFile(string address)
        {
            WebRequest request = WebRequest.Create(address);
            request.Proxy = null;
            using (WebResponse res = request.GetResponse())
            {
                using (Stream s = res.GetResponseStream())
                {
                    using (StreamReader sr = new StreamReader(s))
                    {
                        return sr.ReadToEnd();
                    }
                }
            }
        }


        public IEnumerable<IPAddress> ResolveDNS(string dns)
        {
            return Dns.GetHostAddresses(dns);
        }
        public string GetHostDnsName(string iptarget)
        {
            return Dns.GetHostEntry(iptarget).HostName;
        }
    }
}
